package mx.com.ingsw.query;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import mx.com.ingsw.dao.AlumnoDAO;
import mx.com.ingsw.dao.AsignaturaDAO;
import mx.com.ingsw.model.Alumno;
import mx.com.ingsw.model.Asignatura;
import mx.com.ingsw.model.Comprobante;
import mx.com.ingsw.model.Historial;
import mx.com.ingsw.model.HistorialPK;
import mx.com.ingsw.model.Inscripcion;

public class AlumnoQuery extends AlumnoDAO {

    public List<Inscripcion> BuscaInsc(int cuenta) {
        EntityManager em = getEntityManager();
        Query q = em.createNamedQuery("Inscripcion.findByNoCuenta", Inscripcion.class);
        q.setParameter("noCuenta", cuenta);
        return (List<Inscripcion>) q.getResultList();
    }

    public List<Historial> BuscaHist(int cuenta) {
        EntityManager em = getEntityManager();

        Query q = em.createNamedQuery("Historial.findByNoCuenta", Historial.class);
        q.setParameter("noCuenta", cuenta);
        return (List<Historial>) q.getResultList();
    }

    public String sexo () {
        EntityManager em = getEntityManager();
        try {
            em = getEntityManager();
            Query q1 = em.createQuery("SELECT a.*, p.* FROM Alumno a, Persona p WHERE a.noCuenta=p.idPersona AND p.sexo='F';");
            Query q2 = em.createQuery("SELECT a.*, p.* FROM Alumno a, Persona p WHERE a.noCuenta=p.idPersona AND p.sexo='F';");
           String tam=q1.getResultList().size()+"";
           tam+="/"+q2.getResultList().size()+"";
            return tam;
        } finally {
            em.close();
        }
    }

    public List<Historial> getAsignaturaCreditos(int cuenta) {
        EntityManager em = getEntityManager();
        //try {
            AsignaturaDAO das = new AsignaturaDAO();
            Asignatura as = new Asignatura();

            em = getEntityManager();
            Query q1=em.createNamedQuery("Historial.findByNoCuenta",Historial.class);
            
            q1.setParameter("noCuenta",cuenta);
            return (List<Historial>)q1.getResultList();
            /*Query q1 = em.createQuery("SELECT h FROM Historial h WHERE h.noCuenta = ?1");
            q1.setParameter(1, cuenta);
            List<Historial> listaH = q1.getResultList();
            return listaH;
        } finally {
            em.close();
        }*/
    }
    
    public List<Inscripcion> BuscaInscAll (){
       EntityManager em= getEntityManager();
        Query  q = em.createNamedQuery("Inscripcion.findAll",Inscripcion.class);
            return (List<Inscripcion>)q.getResultList();
    }
    
    public List<Alumno> BuscaAlumAll (){
       EntityManager em= getEntityManager();
        Query  q = em.createNamedQuery("Alumno.findAll",Alumno.class);
            return (List<Alumno>)q.getResultList();
    }
}